package zifuhuanchong;

import java.io.*;
import java.util.ArrayList;
import java.util.function.Consumer;

public class t2 {
    public static void main(String[] args) throws IOException {
//        readObject();
        readAndForeach();

    }

    private static void readAndForeach() throws IOException {
        ArrayList<Student> arrayList = new ArrayList<>();
        BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay13\\src\\main\\java\\zifuhuanchong\\stduent.txt"));
        String s;
        while ((s  = bufferedReader.readLine()) !=null){
            String[] split = s.split("-");
            arrayList.add( new Student(split[0],split[1]));
        }
        arrayList.forEach(item-> System.out.println(item.getName() + "***" + item.getAge()));
    }

    private static void readObject() throws IOException {
        ArrayList<Student> arr =   new ArrayList<Student>();
        arr.add(new Student("张三", "3"));
        arr.add(new Student("李四", "4"));
        arr.add(new Student("王五", "5"));

        BufferedWriter fos =    new BufferedWriter(new FileWriter("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay13\\src\\main\\java\\zifuhuanchong\\stduent.txt"));
        arr.forEach(item->{
            try {
                fos.write((item.getName() + "-" + item.getAge()));
                fos.newLine();

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        fos.close();
    }
}
